import api from './api'

const service = {
    // 1. 新增操作
    add: {
        addData: async (data) => {
            const response = await api.createEvent(data)
            return response.data
        }
    },
    // 2. 查询操作
    read: {
        getData: async (id) => {
            const response = await api.getEventById(id)
            return response.data
        },
        getPageData: async (page, size, queryParam) => {
            const response = await api.getEventPage(page, size, queryParam)
            const data = response.data
            return {
                code: data.code,
                error: data.error,
                message: data.message,
                result: data.result,
                data: data.data,
                list: data.data.records,
                pagination: {
                    current: data.data.current,
                    pages: data.data.pages,
                    size: data.data.size,
                    total: data.data.total
                }
            }
        },
        getListData: async (queryParam) => {
            const response = await api.getEventList(queryParam)
            return response.data
        }
    },
    // 3. 更新操作
    update: {
        modifyData: async (data) => {
            const response = await api.updateEventFull(data.id, data)
            return response.data
        },
        modifyPartialData: async (data) => {
            const response = await api.updateEventPartial(data.id, data)
            return response.data
        }
    },
    // 4. 删除操作
    delete: {
        removeData: async (id) => {
            const response = await api.deleteEventById(id)
            return response.data
        }
    },
    // 5. 导出功能
    export: {

    }
}

export default service
